﻿using Mapster;
using MapsterMapper;
using Microsoft.Extensions.DependencyInjection;

namespace OrderingFoot.Core
{
    /// <summary>
    /// Mapster对象映射配置
    /// </summary>
    public static class MapsterMapperExtensions
    {
        /// <summary>
        /// AddMapsterMapper
        /// </summary>
        public static IServiceCollection AddMapsterMapper(this IServiceCollection services)
        {
            var config = TypeAdapterConfig.GlobalSettings;
            config.Default.AddDestinationTransform((string d) => d ?? string.Empty);
            //config.Default.AddDestinationTransform(DestinationTransform.EmptyCollectionIfNull);IList
            services.AddSingleton(config);
            services.AddTransient<IMapper, ServiceMapper>();

            return services;
        }
    }
}
